package sk.ogame.realm.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sk.ogame.realm.entity.Star;
import sk.ogame.realm.mapper.StarMapper;

import java.util.Collections;
import java.util.List;

/**
 * @author 支绍昆
 * 2023/2/1
 * 星球服务
 **/
@Service
public class StarService {

    @Autowired
    private StarMapper starMapper;

    public void add(Star star) {
        calculateId(star);
        starMapper.insert(Collections.singletonList(star));
    }

    public List<Star> listAll() {
        return starMapper.selectAll();
    }

    public int del(int id){
        return starMapper.delById(id);
    }

    //------------------------------- private ----------------------------------

    private void calculateId(Star star) {
        if (star.getId() > 0) {
            return;
        }
        star.setId(star.getGalaxy() * 100000 + star.getSystem() * 100 + star.getSlot());
    }

}
